﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//属性类型
public enum E_PropType
{
    Hp,          //随机血量
    MaxHp,       //最大血量
    MoveSpeed,   //移动速度
    Atk,         //攻击力
    Def          //防御力
}


public class PropReward : MonoBehaviour
{
    public E_PropType type = E_PropType.Hp;

    public int minVal = 0;
    public int maxVal = 0;

    public GameObject getEff;
    private void OnTriggerEnter(Collider other)
    {
        //玩家才能获取 属性奖励
        if (other.CompareTag("Player"))
        {
            Player obj = other.GetComponent<Player>();
            int randVal = Random.Range(minVal, maxVal);
            obj.AddProp(type, randVal);

            //播放奖励特效
            GameObject eff = Instantiate(getEff, this.transform.position, this.transform.rotation);
            //由于该特效身上挂了音效,需要控制音效和音效音量
            AudioSource audioSource = eff.GetComponent<AudioSource>();
            if (audioSource)
            {
                //根据音乐数据 设置音效大小和是否播放
                //设置音效大小
                audioSource.volume = GameDataMgr.Instance.musicData.audioVolume;
                //音效是否播放
                audioSource.mute = !GameDataMgr.Instance.musicData.audio;
                //避免没有勾选 Play on Awake
                audioSource.Play();
            }
            Destroy(this.gameObject);
        }
    }
}
